<template>
  <h1>员工练习表</h1>
  <input type="text" v-model="emp.name" placeholder="请输入员工姓名">
  <input type="text" v-model="emp.salary" placeholder="请输入员工工资">
  <input type="text" v-model="emp.job" placeholder="请输入员工岗位">
  <button @click="addEmp">点我提交</button>
  <hr>
  <table border="1">
    <tr>
      <th>员工编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(e,index) in empArr">
      <td>{{index+1}}</td>
      <td>{{e.name}}</td>
      <td>{{e.salary}}</td>
      <td>{{e.job}}</td>

    </tr>
  </table>

</template>

<script setup>
import {ref} from "vue";

const empArr = ref([])
const emp = ref({
  name:'',
  salary:'',
  job:''
})

const addEmp = () => {
  console.log(emp.value)
  if (emp.value.name.trim() === '' || emp.value.salary.trim() === '' || emp.value.job.trim() === ''){
    alert('请填写完整信息')
    return;
  }
  empArr.value.push(emp.value)
  console.log(empArr.value)

  emp.value = {
    name:'',
    salary:'',
    job:''
  }
}

</script>

<style scoped>

</style>